import {pageConfig} from '@/config'
import { $ajax } from '@/utils/http'
export default {
    search: function({commit}, data){
        let options = {
            loading: false
        }
        if(data.hasOwnProperty('page') && data.page > 1){
            options.loading = false
        }
        return $ajax("search", pageConfig.public, data, options)
    },
    homepage: function({commit}, data){
        let options = {
            loading: "加载中..."
        }
        if(data.hasOwnProperty('page') && data.page > 1){
            options.loading = false
        }
        return $ajax("first", pageConfig.public, data, options)
    },
    getCate: function({commit}, data){
        return $ajax("getCate", pageConfig.public, data)
    },
    getItems: function({commit}, data){
        let options = {
            loading: "加载中..."
        }
        if(data.hasOwnProperty('page') && data.page > 1){
            options.loading = false
        }
        return $ajax("getItems", pageConfig.public, data, options)
    },
    getNav: function({commit}, data){
        return $ajax("getNav", pageConfig.public, data)
    },    
    news: function({commit}, data){
        let options = {
            loading: "加载中..."
        }
        let extra = data.options;

        if(data.hasOwnProperty('page') && data.page > 1){
            options.loading = false
        }
        if (extra) {
            Object.assign(options, extra);
        }

        return $ajax("news", pageConfig.public, data, options)
    },
    rank: function({commit}, data){
        let options = {
            loading: "加载中..."
        }
        let extra = data.options;
        if (extra) {
            Object.assign(options, extra);
        }
        return $ajax("rank", pageConfig.public, data, options)
    },
    customAd: function({commit}, data){
        return $ajax('http://a.aebrowser.cn/index.php/ad/getAppAd', pageConfig.public, data, {})
    },
}